package asia.lics.web.controller.app;

import asia.lics.common.core.controller.BaseController;
import asia.lics.common.core.domain.AjaxResult;
import asia.lics.common.core.page.TableDataInfo;
import asia.lics.system.domain.FUser;
import asia.lics.system.service.IFUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author ss-tutor
 * @date 2024-12-03
 */
@RestController
@Validated
@RequestMapping("/system/fuser")
public class FUserController extends BaseController {
    @Autowired
    private IFUserService fUserService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:fuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(FUser fUser) {
        startPage();
        List<FUser> list = fUserService.selectFUserList(fUser);
        return getDataTable(list);
    }

    /**
     * 下发vip
     * <p>
     * userId 用户id
     * num 数量
     * unit 单位 0天 1月 2年
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:fuser:vip')")
    @PutMapping("/vip")
    public AjaxResult vip(@NotNull(message = "userId不能为空") Long userId, @NotBlank(message = "num不能为空") String num, @RequestParam(defaultValue = "0") String unit) {
        return toAjax(fUserService.vip(userId, num, unit));
    }
}
